#pragma once
#include <memory>
#include "grid.h"
#include "algorithms.h"

enum class EngineState { Idle, Running, Paused };

struct Stats { int steps=0; int visited=0; int path_len=0; };

class Engine {
    Grid grid;
    std::unique_ptr<Algorithm> algo;
    EngineState state;
    AlgoState last;
    int steps_per_tick;
    int algo_id;
public:
    Engine(int rows, int cols);
    void setAlgorithm(std::unique_ptr<Algorithm> a);
    void setAlgoId(int id);
    int getAlgoId() const;
    const char* algoName() const;
    void setDiagonal(bool v);
    void setStart(Pos p);
    void setGoal(Pos p);
    Grid& getGrid();
    const AlgoState& getAlgoState() const;
    Stats getStats() const;
    void clearObstacles();
    void randomizeObstacles(double ratio, unsigned int seed);
    void toggleRun();
    void pause();
    void resetAlgo();
    void tick();
    void stepOnce();
    void setStepsPerTick(int n);
};

